﻿/**
 * @file display.c
 * @brief this is a brief description
 * @details this is the detail description.
 * @author fulong 
 * @data 7/9/2014
 * @version 1.0
 * @par Copyright (c):
 * @par First build
 *     version: fulong 
 *     data: 7/9/2014
 */
#include "display.h"
#include "../dev/lcd/OCM12232.h"
#include "../lib/font.h"
#include "../dev/uart.h"
#ifdef MENU_ENABLE
#ifndef __SIMPLE_DISPLAY__

#define DISPLAY_MAX_LEN 15

void hal_display_init(void) {
    lcd_init();
    screen_clr();
}
void hal_screen_clr(void) {
    screen_clr();
}
void hal_screen_clr_location(const uint8 x, const uint8 y, const uint8 len) {
    if (y < 2) {
        screen_clr_loction(x, 2 * y, len * 8);
        screen_clr_loction(x, 2 * y + 1, len * 8);
    }
}
/*! \brief 输出文字,支持的文字是utf8编码
 * \param word 要输出的文字,需要utf8编码,不然不能显示.
 * \param x 文字输出的x坐标
 * \param y 文字输出的y坐标
 * \return 
 * \note x,y的定义是字体的大小为16*16,则屏幕宽的像素点总数除以16得到的整数就等于x,同理,屏幕高的像素点总数除以16得到的整数就等于y. 
 */
void hal_display_word(const uint8 x, const uint8 y, const uint8 *word) {
    uint8 k;
    uint8 counter_8 = 0, counter_16 = 0;
    uint16 buf[ DISPLAY_MAX_LEN ] = { 0 };
    utf82unicode(word, buf);
    while (buf[counter_8 + counter_16] != 0) {
        if (buf[counter_8 + counter_16] > 0x7F) {
            for (k = 0; k < FONT_WORD_LEN; k++) {
                if (buf[counter_8 + counter_16] == GB_16[k].index) {
                    display_word(counter_16 * 16 + counter_8 * 8 + x, y * 2, GB_16[k].msk);
                    k = FONT_WORD_LEN;
                    counter_16++;
                }
            }
        } else {
            for (k = 0; k < ASCII_FONT_WORD_LEN; k++) {
                if (buf[counter_8 + counter_16] == GB_8[k].index) {
                    display_ascii(counter_16 * 16 + counter_8 * 8 + x, y * 2, GB_8[k].msk);
                    k = ASCII_FONT_WORD_LEN;
                    counter_8++;
                }
            }
        }
    }
}
#endif
#endif
